package com.petsdar.utils;

import com.petsdar.pojo.Result;

/**
 * Created with IntelliJ IDEA
 * User: heroC
 * Date: 2020/7/2
 * Time: 12:23
 * Description: 避免代码的冗余，创建工具类统一返回Result
 * Version: V1.0
 */
public class ResultUtil {

    /**
     * 返回没有data数据的成功信息
     * @return
     */
    public static String success(){
        return success(null);
    }

    /**
     * 返回有data数据的成功信息
     * @param data
     * @return
     */
    public static String success(Object data){
        Result result = new Result(Constant.HTTP_SUCCESS_CODE, Constant.HTTP_SUCCESS_MSG);
        result.setData(data);
        return result.toString();
    }

    /**
     * 返回没有data数据的失败信息
     * @return
     */
    public static String fail(){
        Result result = new Result(Constant.HTTP_FAIL_CODE, Constant.HTTP_FAIL_MSG);
        return result.toString();
    }
}
